using UnityEngine;
using UnityEngine.SceneManagement;

public class SaveManager : MonoBehaviour
{
	public PlayerManager _PlayerManager;

	public Vector2 ReEnterPosition;

	public Vector2 ReEnterDirection;

	public bool IsPlayableLevel = true;

	private int PreviousLevelIndex;

	public INPUTPOSITION inputPOS;

	public CameraManager _CameraManager;

	private void Start()
	{
		if (PlayerPrefs.GetFloat("HasSceneTransition") == 0f)
		{
			LoadSceneTransitionPlayerPosition();
		}
		_CameraManager = ((Component)Camera.main).gameObject.GetComponent<CameraManager>();
	}

	public void ResetData()
	{
		PlayerPrefs.DeleteAll();
	}

	public void SaveIntValue(string IntName, int IntValue)
	{
		PlayerPrefs.SetInt(IntName, IntValue);
		PlayerPrefs.Save();
		Debug.Log((object)("Game data saved! | " + IntName + " : " + IntValue));
	}

	public void SceneTransitionPlayerPosition(Vector3 PlayerPos)
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		Scene activeScene = SceneManager.GetActiveScene();
		PlayerPrefs.SetInt("VISITED" + ((Scene)(ref activeScene)).name, 1);
		PlayerPrefs.SetInt("HasSceneTransition", 1);
		activeScene = SceneManager.GetActiveScene();
		PlayerPrefs.SetInt("PreviousScene", ((Scene)(ref activeScene)).buildIndex);
	}

	public void LoadSceneTransitionPlayerPosition()
	{
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_0077: Unknown result type (might be due to invalid IL or missing references)
		//IL_009d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
		MonoBehaviour.print((object)PlayerPrefs.GetInt("PreviousScene"));
		if (PlayerPrefs.GetInt("PreviousScene") == inputPOS.SceneNameIndex[PreviousLevelIndex])
		{
			MonoBehaviour.print((object)("Last Level was " + PlayerPrefs.GetInt("PreviousScene")));
			((Component)_PlayerManager).transform.position = Vector2.op_Implicit(inputPOS.StartPosition[PreviousLevelIndex]);
			_PlayerManager._PMove.RotatePlayerAnim(inputPOS.StartDirection[PreviousLevelIndex]);
			((Component)_CameraManager).transform.position = inputPOS.StartCameraPosition[PreviousLevelIndex];
		}
		else if (PreviousLevelIndex != inputPOS.SceneNameIndex.Length)
		{
			PreviousLevelIndex++;
			LoadSceneTransitionPlayerPosition();
		}
		else
		{
			Debug.Log((object)"No Scene Position!");
		}
	}

	private void LoadIntValue(string IntName, int IntValue)
	{
		if (PlayerPrefs.HasKey(IntName))
		{
			PlayerPrefs.GetInt(IntName);
			Debug.Log((object)"Game data loaded!");
		}
		else
		{
			Debug.LogError((object)(IntName + " Does not exist!"));
		}
	}

	private void Update()
	{
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		if (Input.GetKey((KeyCode)114))
		{
			ResetData();
			Scene activeScene = SceneManager.GetActiveScene();
			SceneManager.LoadScene(((Scene)(ref activeScene)).buildIndex);
		}
	}
}
